package com.studyweb.service.impl;

import com.studyweb.mapper.WritingMaterialAccumulationMapper;
import com.studyweb.pojo.entity.WritingMaterialAccumulation;
import com.studyweb.service.WritingMaterialAccumulationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class WritingMaterialAccumulationServiceImpl implements WritingMaterialAccumulationService {
    
    @Autowired
    private WritingMaterialAccumulationMapper writingMaterialAccumulationMapper;
    
    @Override
    public List<WritingMaterialAccumulation> list() {
        return writingMaterialAccumulationMapper.list();
    }
    
    @Override
    public WritingMaterialAccumulation getById(Long id) {
        return writingMaterialAccumulationMapper.getById(id);
    }
    
    @Override
    public void add(WritingMaterialAccumulation writingMaterialAccumulation) {
        writingMaterialAccumulation.setStatus(0); // 默认状态为正常
        writingMaterialAccumulationMapper.insert(writingMaterialAccumulation);
    }
    
    @Override
    public void update(WritingMaterialAccumulation writingMaterialAccumulation) {
        writingMaterialAccumulationMapper.update(writingMaterialAccumulation);
    }
    
    @Override
    public void delete(Long id) {
        writingMaterialAccumulationMapper.deleteById(id);
    }
    
    @Override
    public void batchDelete(List<Long> ids) {
        if (ids != null && !ids.isEmpty()) {
            writingMaterialAccumulationMapper.batchDeleteByIds(ids);
        }
    }
    
    @Override
    public List<WritingMaterialAccumulation> search(String keyword) {
        return writingMaterialAccumulationMapper.listByKeyword(keyword);
    }
}